<?php

namespace frontend\models;

use common\helps\tools;
use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
use yii\db\Exception;
use yii\db\Query;

/**
 * This is the model class for table "ProjectPicture".
 *
 */
class ProjectPicture extends ActiveRecord
{
    public $type;// 操作类型
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%project_picture}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return[
            [['picture'], 'trim'],
            [['picture','project_id'], 'required', 'message'=>'{attribute}不能为空'],
            [['id','project_id','type'], 'match', 'pattern' => '/^[1-9][0-9]*$/','message'=>'{attribute}值无效'],
        ];
    }


    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '项目海报id',
            'picture' => '海报图地址名称',
            'project_id'=>'项目id',
            'type'=>'操作类型',
        ];
    }

    public function scenarios()
    {
        return [
            'default' => [
                'picture',
                'project_id',
                'created_at',
                'updated_at',
                'deleted_at',
                'type',
            ],
            'pre_update' => [
                'id',
                'type',
            ],
            'create' => [
                'picture',
                'project_id',
                'created_at',
                'updated_at',
                'deleted_at',
            ],
            'update'=>[
                'id',
                'picture',
                'project_id',
                'created_at',
                'updated_at',
                'deleted_at',
            ],
        ];
    }



    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            TimestampBehavior::className(),
        ];
    }


    /**
     * 获取项目海报列表
     * @param $params
     * @author hey_heyang(635870453@qq.com)
     * @return array
     */
    public function getProjectPictureList($params){
        $condition['deleted_at'] = null;
        $condition['project_id'] = intval($params['project_id']);
        $list = $this->find()->where($condition)->asArray()->all();
        return empty($list)?array():$list;

    }


}
